// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <QtGui/QRegExpValidator>
#include <QtCore/QRegExp>
#include <QtGui/QLabel>
#include <QtGui/QTextBrowser>
#include <QtGui/QStyle>

#include "ui/introscreen.h"
#include "ui/browser.h"
#include "ui/support.h"
#include "ui/wizard.h"
#include "util/provider.h"

namespace popdiag {

IntroScreen::IntroScreen(QWidget *parent) : QWizardPage(parent) {
}

IntroScreen::~IntroScreen() {
  // the _field members clean themselves up using the Qt "parent object"
  // memory cleanup model.
}

void IntroScreen::SetupUI() {
  QVBoxLayout *layout = new QVBoxLayout();
  QLabel *title = new QLabel(this);
  QString title_text = "<h1>";
#ifdef COMPANY_NAME
  title_text += tr("Getting started with the %1 POP and IMAP Troubleshooter",
                   "The name of the first step of the wizard. "
                   "%1 is the company name")
                  .arg(COMPANY_NAME);
#else
  title_text += tr("Getting started with the POP and IMAP Troubleshooter",
                   "The name of the first step of the wizard, "
                   "without a company name");
#endif
  title_text += "</h1><p></p>";
  title->setText(title_text);
  title->setWordWrap(true);
  layout->addWidget(title);
  Browser *purpose = new Browser(this, QSize(400, 400));
  QString purpose_text;
  purpose_text += tr("This tool will quickly detect POP and IMAP "
                     "email access problems and provide instructions on how "
                     "to fix them.",
                     "Explains the purpose and scope of this tool");
  // intentionally not translated:
  if (provider->HasSupportLinks()) {
    purpose_text += "<br><a href=\"";
    purpose_text += provider->GetSupportLink(Support::TOOL_PURPOSE) + "\">";
    purpose_text += tr("Learn more",
                      "A label for a hyperlink that will open "
                      "a browser and display additional external "
                      "help text about this tool.");
    purpose_text += "</a>";
  }
  purpose_text += "</p><p></p><p>";
  purpose_text += tr("Before you begin:",
                     "Heading for a bulleted list of required actions");
  purpose_text += "<ul><li>";
  purpose_text += tr("<b>Make sure you're at the computer with POP or "
                     "IMAP problems.</b>",
                     "Asks the user to run this program from the computer "
                     "experiencing the problem they would like to diagnose");
  // the whitespace line doesn't render without the &nbsp;:
  purpose_text += "<br>&nbsp;</li><li>";
  purpose_text += tr("<b>Have your username and password handy.</b>",
                     "Asks the user to know their login credentials");
  purpose_text += "</li></ul></p>";
  purpose->setHtml(purpose_text);
  layout->addWidget(purpose);

  setLayout(layout);
}

}  // namespace popdiag
